package com.sure.supermarketserver.stock.maintenance;

import com.sure.supermarketserver.common.CommonService;
import com.sure.supermarketserver.common.Result;
import com.sure.supermarketserver.common.TokenUtils;
import com.sure.supermarketserver.stock.maintenance.MaintenanceDto;
import com.sure.supermarketserver.stock.maintenance.MaintenanceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/stock/maintenance")
public class MaintenanceAPI {

    @Resource
    private MaintenanceService MaintenanceService;

    @Resource
    private CommonService commonService;

    @GetMapping("")
    public Result maintenanceList(MaintenanceDto dto) {
        Map<String, Object> page = MaintenanceService.findMaintenanceList(dto);
        return Result.success(page);
    }

    @PostMapping("")
    public Result maintenanceAdd(@RequestBody MaintenanceDto dto,@RequestHeader("Token") String token) {
        dto.setSt_id(TokenUtils.getUserInfo(token,commonService).getUserId());
        MaintenanceService.addMaintenance(dto);
        return Result.success();
    }

    @DeleteMapping("{id}")
    public Result maintenanceDel(@PathVariable String id) {
        MaintenanceService.delMaintenance(id);
        return Result.success();
    }

    @PutMapping("")
    public Result supplierUpd(@RequestBody MaintenanceDto dto) {
        MaintenanceService.updMaintenance(dto);
        return Result.success();
    }
}
